var express = require('express');
var router = express.Router();
var {typeModel,shopModel} = require('../../../model/model')

/* GET home page. */
router.get('/', function(req, res, next) {
   // res.render('index', { title: 'Express' });
   res.send('hello world');
});

//添加商品
router.post('/shopadd',async(req,res)=>{
   shopModel.create(req.body)
   res.send({
      code:200,
      msg:'添加成功',
      value:req.body
   })
})

//获取商品
router.get('/shoplist',async(req,res)=>{
   //获取商品列表并且连接type表其中shop表的字段是type,一次性出来
   let data = await shopModel.find().populate('type')
   let type = await typeModel.find()
   res.send({
      code:200,
      msg:'获取成功',
      data:data,
      type:type,
   })
})

module.exports = router;
